﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CapaEntidades;
using System.Data;
using System.Data.SqlClient;

namespace CapaDatos
{
    public class datCliente{
        #region singleton
            private static readonly datCliente _instancia = new datCliente();
            //private datCliente();
            public static datCliente Instancia{
                get { return datCliente._instancia; }
            }
        #endregion

        #region Metodos
            public entCliente VerificarAcceso(String prmUser, String prmPass) {
            entCliente c = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            try
            {                
                SqlConnection conex = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("spVerificarAcceso", conex);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@prmUsuario", prmUser);
                cmd.Parameters.AddWithValue("@prmPassword", prmPass);
                conex.Open();
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    c = new entCliente();
                    c.idCliente = Convert.ToInt16(dr["idCliente"]);
                    c.RazonSocial = dr["RazonSocial"].ToString();
                    c.RUC = dr["RUC"].ToString();
                    c.direccion = dr["direccion"].ToString();
                    c.Telefono = dr["Telefono"].ToString();
                }
            }
            catch (Exception e){
                c = null;   throw e;
            }finally {
                cmd.Connection.Close();
            }
            return c;
            }
        #endregion
    }
}
